﻿#pragma once
#include "AngelScriptBinder.h"

_NAMESPACE_BEGIN

class TriggerReport;

/// 物理触发器状态
enum TriggerStatus
{
	/// 进入触发
	TRIGGER_ENTER,

	/// 离开触发
	TRIGGER_LEAVE
};

/// 触发信息结构
struct TriggerInfor
{
	TriggerInfor()
	{
		triggerShape=otherShape=NULL;
	}
	NxShape* triggerShape,*otherShape;
	int      status;
};

/// 脚本中使用的触发器事件
class TriggerEvent:public ASEvent
{
public:
	TriggerEvent(){};
	void operator()(CONST_REF(TriggerInfor) infor)
	{
		if(!pcaller) return;
		Prepare();
		int t=ctx->SetArgObject(0,(void*)&infor);	assert(t>=0);			
		Execute();
	}
	void callEvent(CONST_REF(TriggerInfor) infor)
	{
		if(!pcaller) return;
		Prepare();
		int t=ctx->SetArgObject(0,(void*)&infor);	assert(t>=0);			
		Execute();
	}
};

/// 本项目中自定义的触发器事件回调类
/// 当有满足条件的出发时，PhysX会自动调用本类实例化的单体对象

class TriggerReport : public NxUserTriggerReport
{
public:
	/// 单体类声明
	SINGLETON_HELPER(TriggerReport)

	/// 默认构造
	TriggerReport(){};

	/// PhysX SDK调用的触发回调
	void onTrigger(NxShape& triggerShape, NxShape& otherShape, NxShapeFlag status);

	TriggerEvent event;
};

_NAMESPACE_END